/**
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package br.biofoco.p2p.utils;

import java.util.Date;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import br.biofoco.p2p.services.AsyncToken;
import br.biofoco.p2p.services.ServiceResult;

public class XMLUtils {
	
	private static final String XML_ENCODING = "ISO-8859-1";

	private XMLUtils() {}
	
	public static String serializeList(String rootName, String elementName, Iterable<?> stringList){
		Document document = DocumentHelper.createDocument();
		document.addComment("Generated at " + new Date());
		document.setXMLEncoding(XML_ENCODING);
        Element root = document.addElement( rootName );

        for (Object obj : stringList){
        	root.addElement(elementName)
        		.addText(obj.toString());
        }
        return document.asXML();
	}

	public static String serializeResult(ServiceResult<?> result) {
		throw new UnsupportedOperationException("Operation not supported!");
//		XStream xstream = new XStream();
//		xstream.alias("Result", BioResult.class);
//		return xstream.toXML(result);
	}

	public static String serializeToken(AsyncToken asyncToken) {
		throw new UnsupportedOperationException("Operation not supported!");		
//		XStream xstream = new XStream();
//		xstream.alias("Token", AsyncToken.class);
//		return xstream.toXML(asyncToken);
	}
}
